def print_hi(name):
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

if __name__ == '__main__':
    print_hi('auto_kpi')

from openpyxl import load_workbook

wb_read = load_workbook(r"E:\lme\KPI\产品研发部2月考勤.xlsx")  # 获取已存在的工作簿
wb_write = load_workbook(r"E:\lme\KPI\2023年01月员工基本行为考评表产品研发部.xlsx")  # 获取已存在的工作簿

sheet = wb_read.active

def check_in(pos, name):
    forget_count = sheet.cell(pos, 21)  # 忘打卡次数
    if forget_count.value is None:
        forget_count = 0
    else:
        forget_count = forget_count.value

    belate_count = sheet.cell(pos, 22)  # 迟到次数
    if belate_count.value is None:
        belate_count = 0
    else:
        belate_count = belate_count.value

    overtime = sheet.cell(pos, 23)  # 加班时间
    if overtime.value is None:
        overtime = 0
    else:
        overtime = overtime.value

    kpi_rate = 1.0
    if overtime >= 65:
        kpi_rate = 1.5
    elif overtime >= 55:
        kpi_rate = 1.4
    elif overtime >= 45:
        kpi_rate = 1.3
    elif overtime >= 35:
        kpi_rate = 1.2
    elif overtime >= 25:
        kpi_rate = 1.1
    else:
        kpi_rate = 1.0

    ws = wb_write[name]
    # 修改月份
    cell_name = ws.cell(1, 1)
    cell_name.value = "2023年02月月度基本行为考评表"
    # 计算靠勤分
    cell_score = ws.cell(7, 10)
    cell_score.value = 10 - forget_count - belate_count
    # 计算月度绩效
    cell_score_row = 15
    if name == "郭季红" or name == "李秋萍":
        cell_score_row = 14
    cell_pki = ws.cell(cell_score_row, 9)
    cell_pki.value = kpi_rate

    print(str(cell_score.value) + " " + str(cell_pki.value) + " " + name)
    return None

names = ["杨超", "熊海峰", "黄杏", "伍成乾", "李富林", "郭季红", "钟仁炜", "刘锡", "赵杰", "罗泽", "李秋萍"]

pos = 4;
for x in names:
    check_in(pos, x)
    pos += 1

wb_write.save(r"E:\lme\KPI\2023年02月员工基本行为考评表产品研发部.xlsx")
